package com.qian.ddj.web.controller;

import com.qian.api.ddj.model.Business;
import com.qian.api.ddj.model.BusinessCard;
import com.qian.api.ddj.service.IBusinessCardService;
import com.qian.api.ddj.service.IBusinessService;
import com.yaowk.api.common.PageReq;
import com.yaowk.api.common.PageResp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/ddj/business")
@Api(tags = "商户管理")
public class BusinessController {

    @Autowired
    private IBusinessService businessService;
    @Autowired
    private IBusinessCardService businessCardService;

    @GetMapping("/list/{id}")
    @ApiOperation("商户列表")
    public PageResp<Business> list(@PathVariable Integer id, PageReq pageReq) {
        Business business = new Business();
        business.setGroupId(id);
        PageResp pageResp = businessService.findAll(business, pageReq);
        return pageResp;
    }

    @PostMapping
    @ApiOperation("保存商户")
    public Business save(Business business) {
        business = businessService.save(business);
        return business;
    }

    @ApiOperation("禁用")
    @GetMapping("/stop/{id}")
    public void stop(@PathVariable Integer id) {
        List<Integer> businessIds = new ArrayList<>();
        businessIds.add(id);
        businessService.stop(businessIds);
    }

    @ApiOperation("启用")
    @GetMapping("/start/{id}")
    public void start(@PathVariable Integer id) {
        List<Integer> businessIds = new ArrayList<>();
        businessIds.add(id);
        businessService.start(businessIds);
    }

    @ApiOperation("商户银行卡")
    @GetMapping("/businessCard/{groupId}")
    public List<BusinessCard> businessCards(@PathVariable Integer groupId) {
        BusinessCard businessCard = new BusinessCard();
        businessCard.setBusinessGroupId(groupId);
        List<BusinessCard> list = businessCardService.findAll(businessCard);
        return list;
    }

}
